<!--
    医生审核页面
    温世杰
 -->
 <template>
  <div>
    <el-card style="margin-bottom: 10px">
      <el-input
        v-model="doctorName"
        style="width: 200px"
        placeholder="请输入昵称"
        suffix-icon="el-icon-message"
      ></el-input>
      <el-button
        class="custom-button ml-10"
        icon="el-icon-search"
        @click="load()"
        >搜索</el-button
      >
    </el-card>
    <el-card>
      <el-table :data="tableData" border stripe height="600">
        <el-table-column prop="personalPhotos" label="医生个人照片" width="120">
          <template slot-scope="scope">
            <el-image :src="$imageUrl + scope.row.personalPhotos"></el-image>
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="医生姓名" width="120" />
        <el-table-column prop="userSex" label="性别" width="60">
          <template slot-scope="scope">
            {{
              scope.row.userSex == 0 ? "男" : scope.row.userSex == 1 ? "女" : ""
            }}
          </template>
        </el-table-column>
        <el-table-column prop="doctorAge" label="年龄" width="80">
          <template slot-scope="scope"> {{ scope.row.doctorAge }}岁</template>
        </el-table-column>
        <el-table-column prop="address" label="地址" width="150" />
        <el-table-column prop="job" label="是否在职" width="100">
          <template slot-scope="scope">
            {{ scope.row.job == 1 ? "在职" : scope.row.job == 2 ? "离职" : "" }}
          </template>
        </el-table-column>
        <el-table-column prop="hospital" label="所属医院" width="180" />
        <el-table-column prop="department" label="科室" width="120" />
        <el-table-column prop="title" label="职称" width="120" />
        <el-table-column prop="life" label="从业年限" width="80">
          <template slot-scope="scope"> {{ scope.row.life }}年</template>
        </el-table-column>
        <el-table-column prop="auditStatus" label="审核状态" width="120">
          <template slot-scope="scope">
            <el-tag effect="plain" v-if="scope.row.auditStatus == 0"
              >待审核</el-tag
            >
            <el-tag
              effect="plain"
              class="pass_button"
              type="success"
              v-if="scope.row.auditStatus == 1"
              >审核通过</el-tag
            >
            <el-tag
              effect="plain"
              type="danger"
              v-if="scope.row.auditStatus == 2"
              >审核未通过</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              class="pass_button"
              @click="getInfo(scope.row)"
              icon="el-icon-info"
              >详情
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页 -->
    <el-pagination
      class="pageAll"
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="5"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      style="text-align: center"
    >
    </el-pagination>
    <!-- 审核医师-->
    <el-dialog title="审核医师" :visible.sync="phyViews" width="60%">
      <el-descriptions :column="3" size="small" border>
        <template slot="extra" v-if="phyInfo.auditStatus == 0">
          <el-button
            @click="delDoctorInfo(phyInfo)"
            class="custom-button"
            icon="el-icon-check"
            size="small"
            >通过</el-button
          >
          <el-button
            @click="delDoctorInfo1(phyInfo)"
            class="custom-buttonT"
            icon="el-icon-close"
            size="small"
            >驳回</el-button
          >
        </template>
        <el-descriptions-item label="用户名">
          {{ phyInfo.userName }}
        </el-descriptions-item>
        <el-descriptions-item label="手机号">
          {{ phyInfo.userPhone }}
        </el-descriptions-item>
        <el-descriptions-item label="头像">
          <el-image
            :src="$imageUrl + phyInfo.imageId"
            class="avatar"
          ></el-image>
        </el-descriptions-item>
        <el-descriptions-item label="居住地">
          {{ phyInfo.address }}
        </el-descriptions-item>
        <el-descriptions-item label="性别">
          {{ phyInfo.userSex == 1 ? "男" : "女" }}
        </el-descriptions-item>
        <el-descriptions-item label="年龄">
          {{ phyInfo.doctorAge }}
        </el-descriptions-item>

        <el-descriptions-item label="生日">
          {{ phyInfo.userBirthday }}
        </el-descriptions-item>
        <el-descriptions-item label="是否在职">
          <el-tag size="small" v-if="phyInfo.job == 1">在职</el-tag>
          <el-tag type="info" v-else size="small">离职</el-tag>
        </el-descriptions-item>
        <el-descriptions-item label="任职医院">
          {{ phyInfo.hospital }}
        </el-descriptions-item>
        <el-descriptions-item label="所属医院">
          {{ phyInfo.department }}
        </el-descriptions-item>
        <el-descriptions-item label="科室">
          {{ phyInfo.department }}
        </el-descriptions-item>
        <el-descriptions-item label="职称">
          {{ phyInfo.title }}
        </el-descriptions-item>
        <el-descriptions-item label="从业年限">
          {{ phyInfo.life }}年
        </el-descriptions-item>
        <el-descriptions-item label="身份证号">
          {{ phyInfo.identityNumber }}
        </el-descriptions-item>
        <el-descriptions-item label="医师证号">
          {{ phyInfo.physicianNumber }}
        </el-descriptions-item>
        <el-descriptions-item label="执业证书">
          <el-image
            :src="$imageUrl + phyInfo.certificatePhoto"
            class="avatar"
          ></el-image>
        </el-descriptions-item>
        <el-descriptions-item label="个人照片">
          <el-image
            :src="$imageUrl + phyInfo.personalPhotos"
            class="avatar"
          ></el-image>
        </el-descriptions-item>
        <el-descriptions-item label="申请时间">
          {{ phyInfo.submitTime }}
        </el-descriptions-item>
        <el-descriptions-item label="审核时间">
          {{ phyInfo.auditTime }}
        </el-descriptions-item>
        <el-descriptions-item label="审核管理员">
          {{ phyInfo.auditor }}
        </el-descriptions-item>
        <el-descriptions-item label="审核结果">
          <el-tag effect="plain" v-if="phyInfo.auditStatus == 0">待审核</el-tag>
          <el-tag
            effect="plain"
            class="pass_button"
            type="success"
            v-if="phyInfo.auditStatus == 1"
            >审核通过</el-tag
          >
          <el-tag effect="plain" type="danger" v-if="phyInfo.auditStatus == 2"
            >审核未通过</el-tag
          >
        </el-descriptions-item>
        <el-descriptions-item label="审核意见">
          {{ phyInfo.auditComment }}
        </el-descriptions-item>
      </el-descriptions>
    </el-dialog>
  </div>
</template>

<script>
// import  request  from '@/utils/request.js'
import { v4 as uuidv4 } from "uuid";
import dateUtil from "../../util/date";
export default {
  computed: {
    //当前登录用户
    userId() {
      return this.$store.state.user.userId;
    },
  },
  data() {
    return {
      //详情内容
      phyInfo: {},
      //详情弹窗
      phyViews: false,
      //分页
      currentPage4: 1,
      // 表格数据
      tableData: [],
      pageNum: 1, // 条数
      pageSize: 5, // 页数
      total: 0, // 初始值
      loginName: window.sessionStorage.getItem("loginName"), //当前登录者loginName
      msg: [],
      toUserId: "",
      type: "app", //系统信息
      avatarUrl: "",
      // 模糊查搜索框数值
      id: 0,
      doctorName: "",
      // 消息接收人
      inceptId: 1,
      checkType: 2,
      // 消息
      content: "您申请的成为医生已经通过，请重新登陆启用权限",
      contents: "很遗憾您申请成为医生失败，如再次申请请材料齐全后再次申请",
      inceptIds: [],
      // 接收人对象
      inceptForm: {},
      // 聊天内容
      lt: {
        content: "",
        toUserId: "",
        type: "check-person",
        uuid: "", //获取随机id,
        checkType: "2",
        createTime: "",
      },
    };
  },
  mounted() {
    //新开
    this.load();
  },
  // 方法集合
  methods: {
    //打开医师详情
    getInfo(row) {
      //打开窗口
      this.phyViews = true;
      //赋值
      this.phyInfo = row;
    },

    // 发送消息 通过
    sendMsg(userId) {
      if (this.content.trim() !== "") {
        let lt = {
          toUserId: userId, //发送人
          checkReason: this.content, // 发送信息内容
          checkType: this.checkType,
          uuid: this.userId + uuidv4(),
          createTime: dateUtil.getMinuteNow(), //获取现在时间
          type: "check-person",
          isRead: 0,
        };
        // 发送消息
        this.$websocket.ws.send(JSON.stringify(lt));
      } else {
        this.message("不能发送空消息", "warning");
        // 清除文本框空格
        this.content = this.content.trim();
      }
    },
    //获取现在时间
    getNowTime() {
      return dateUtil.getTimeNow();
    },
    // 发送消息  不通过
    sendMsgs(userId, text) {
      if (this.content.trim() !== "") {
        let lt = {
          toUserId: userId, //发送人
          checkReason: this.contents + ",原因是：" + text, // 发送信息内容
          checkType: this.checkType,
          uuid: this.userId + uuidv4(),
          createTime: dateUtil.getMinuteNow(), //获取现在时间
          type: "check-person",
          isRead: 0,
        };
        // 发送消息
        this.$websocket.ws.send(JSON.stringify(lt));
      } else {
        this.message("不能发送空消息", "warning");
        // 清除文本框空格
        this.content = this.content.trim();
      }
    },
    //加载数据
    load() {
      this.$axios
        .get("/physician/physicianList", {
          params: {
            doctorName: this.doctorName,
            pageNum: this.pageNum,
            pageSize: this.pageSize,
          },
        })
        .then((res) => {
          this.tableData = res.data.data.content;
          this.total = res.data.data.totalSize;
        })
        .catch((err) => {
          console.log(err);
        });
    },
    delDoctorInfo(data) {
      // 审核通过
      this.$confirm("此操作将审核通过该医师，是否继续？", "提示", {
        cofirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then((res) => {
          let from = {
            auditor: this.loginName, //当前登录者
            doctorId: data.userId, //医师id
          };
          this.$axios
            .post("/physician/requestOk", from)
            .then((res) => {
              if (res.status === 200) {
                this.myMessage("success", "审核通过成功！");
                this.phyViews = false;
                //关闭
                this.load();
                this.sendMsg(data.userId);
                this.data.userId = this.toUserId;
              } else {
                this.myMessage("warning", "审核通过失败！");
              }
            })
            .catch((res) => {});
        })
        .catch(() => {
          this.myMessage("info", "已取消审核通过");
        });
    },
    delDoctorInfo1(data) {
      this.$prompt("请输入驳回原因", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
      })
        .then(({ value }) => {
          let from = {
            auditor: this.loginName, //当前登录者
            doctorId: data.userId, //医师id
            auditComment: value, //医师id
          };
          this.$axios
            .post("/physician/requestNo", from)
            .then((res) => {
              if (res.status === 200) {
                this.myMessage("success", "审核驳回成功！");
                this.phyViews = false;
                this.load();
                this.sendMsgs(data.userId, value);
                this.data.userId = this.toUserId;
              } else {
                this.myMessage("warning", "审核驳回失败！");
              }
            })
            .catch((res) => {});
        })
        .catch(() => {
          this.myMessage("info", "已取消审核驳回");
        });
    },
    handleSizeChange(val) {
      // 改变每页条数
      this.pageSize = val;
      this.load();
    },
    handleCurrentChange(val) {
      // 改变当前页
      this.pageNum = val;
      this.load();
    },
    myMessage(type, message) {
      this.$message({
        message: message,
        type: type,
      });
    },
  },
};
</script>

<style scoped>
html.body {
  height: 100%;
}
.ml-5 {
  margin-left: 5px;
}
.mr-5 {
  margin-right: 5px;
}
.pd-10 {
  padding: 10px 0;
}
::v-deep .el-image__inner {
  vertical-align: top;
  width: 74px;
  height: 74px;
}
</style>
